<template>
  <div class="itemMusicList">
    <!-- 收藏、播放全部 -->
    <div class="itemListTop">
      <div class="listLeft">
        <span
          >播放全部<span>(共{{ itemList.length }}首)</span></span
        >
      </div>

      <div class="listRight">
        <span>收藏({{ subscribedCount }})</span>
      </div>
    </div>

    <!-- 歌单 -->
    <div class="itemList">
      <div class="item" v-for="(item, i) in itemList" :key="i" @click="playMusic(i)">
        <!-- 点击将歌曲信息传递给播放列表 -->
        <div class="itemLeft">
          <!-- 编号 -->
          <span class="leftSpan">{{ i + 1 + '.' }}</span>
          <div>
            <!-- 歌曲名称 -->
            <p>{{ item.name }}</p>
            <!-- 作者 -->
            <span v-for="(item1, index) in item.ar" :key="index">{{ item1.name }}</span>
          </div>
        </div>
        <!-- mv 图标 -->
        <div class="itemRight">
          <!-- mv图标 -->
          <div class="icon bofang" aria-hidden="true" v-if="item.mv != 0">
            <img src="@/assets/img/播放MV.svg" alt="" />
          </div>
          <!-- 更多 -->
          <div class="icon liebiao" aria-hidden="true">
            <img src="@/assets/img/首页.svg" alt="" />
          </div>
        </div>
      </div>
    </div>
    <!--  -->
  </div>
</template>

<script>
import { mapMutations } from 'vuex'

export default {
  setup(props) {
    // console.log(props)
  },
  props: ['itemList', 'subscribedCount'],
  methods: {
    // 点击歌曲信息的放法
    playMusic: function (i) {
      // 调用 vuex 中定义好的 函数，将歌曲信息传递过去
      this.updatePlayList(this.itemList)
      // 歌曲信息的索引
      this.updatePlayListIndex(i)
      // console.log(this.itemList) 检测的是否被点击
    },
    ...mapMutations(['updatePlayList', 'updatePlayListIndex']),
  },
}
</script>

<style lang="less" scoped>
.itemMusicList {
  width: 100%;
  height: 47rem;
  background-color: #fff;
  padding: 0 0.2rem;
  margin-top: 2rem;
  border-top-left-radius: 0.6rem;
  border-top-right-radius: 0.4rem;
  .itemListTop {
    width: 100%;
    height: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .listLeft {
      width: 3rem;
      height: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .icon {
        stroke: #333333;
        stroke-width: 20;
      }
      // 播放全部
      span {
        font-weight: 700;
        display: block;
        position: relative;
        bottom: -1.5rem;
        span {
          width: 100px;
          font-weight: 400;
          font-size: 0.24rem;
          color: #999;
          position: relative;
          right: -4rem;
          top: -1.4rem;
        }
      }
    }
    // 收藏
    .listRight {
      display: flex;
      align-items: center;
      background-color: red;
      padding: 0.2rem;
      border-radius: 0.4rem;
      color: #fff;
      margin-top: 2rem;
      .icon {
        width: 0.3rem;
        height: 0.3rem;
        fill: #fff;
        margin-right: 0.1rem;
        stroke: #fff;
        stroke-width: 50;
      }
    }
  }
  // 歌单
  .itemList {
    width: 100%;
    margin-top: 2rem;

    .item {
      width: 100%;
      height: 2rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      // 歌曲间距
      padding: 2rem;
      .itemLeft {
        width: 85%;
        height: 100%;
        display: flex;
        align-items: center;

        .leftSpan {
          display: inline-block;
          width: 0.2rem;
          text-align: center;
        }
        div {
          p {
            width: 5.6rem;
            height: 1.5rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-weight: 800;
            padding-bottom: 1.5rem;
          }
          span {
            font-weight: 400;
            font-size: 0.01rem;
            color: #999;
          }
          margin-left: 1.5rem;
        }
      }

      .itemRight {
        width: 20%;
        height: 100%;
        display: flex;
        // justify-content: space-between;
        align-items: center;
        position: relative;
        .icon {
          fill: #999;
        }
        // 播放图标
        .bofang {
          position: absolute;
          left: 0;
          img {
            width: 1.5rem;
          }
        }
        // 更多图标
        .liebiao {
          position: absolute;
          right: 0;
          img {
            width: 1.5rem;
          }
        }
      }
    }
    .item:hover {
      background-color: #ccc;
    }
  }
}

</style>
